<?php
namespace BoxSns\Controller\Home;
//use Think\Controller;
class IndexController extends CommonController {
	public function _initialize() {
		parent::_initialize();
		$this->nav_cur = "Home";
	}

	public function index() {
		$this->group_name = "声声慢社区";
		$this->group_ico = "/group/15096.jpg";
		$this->group_count = BoxModel("sns_topic")->where("store_id='$this->store_id' and is_show=1")->count();
		$this->cate_list = BoxModel("sns_group")->get("type='group' and store_id='$this->store_id' and is_show=1");
		$where = "store_id='$this->store_id'";
		$this->group_id = $group_id = I('group_id', "0", "intval");
		if ($group_id) {
			$where .= " and pid=$group_id";
		}
		if ($user_id = I('user_id')) {
			$where .= " and user_id=$user_id";
		}
		$this->groupdata = BoxModel("sns_group")->where(array('id' => $group_id))->find();
		if ($this->groupdata) {
			$this->group_count = BoxModel("sns_topic")->where("store_id='$this->store_id' and is_show=1 and pid='$group_id'")->count();
		}
		$this->pageName = $this->pageName . "_" . $group_id;
		$this->where = $where;
		$this->display();
	}

	/******详情**/
	public function detail() {
		$this->topic_id = I('topic_id');
		$this->data = BoxModel("sns_topic")->load($this->topic_id);
		$this->display();
	}

	/********回复***/
	public function add_comment() {
		$this->pid = I('topic_id');
		$this->comment_id = I('comment_id');
		$this->data = BoxModel("SnsTopic")->load($this->pid);
		$this->tip_title = strip_tags($this->data['title']);
		$this->type = "group";
		if ($this->comment_id) {
			$data = BoxModel("SnsComment")->load("group", $this->comment_id);
			if ($data) {
				$this->pid = $data['pid'];
				$this->data = $data['pidData'];
				$this->to_user_id = $data['user_id'];
				$this->tip_title = strip_tags($data['content']);
			}
		}
		$this->display();
	}

	public function addTopic() {
		$data = I();
		$r = Logic('BoxSns', 'Topic')->add($data);
		echo json_encode($r);

	}

	/********回答***/
	public function do_comment() {
		$row = array(
			'content' => I('content'), //必填
			'pid' => I('pid'),
			'type' => I('type'), //
			'to_comment_id' => I('to_comment_id', "0", "intval"),
		);
		$r = Logic('BoxSns', 'Comment')->add($row);
		echo json_encode($r);
	}

	//删除评论
	public function del_comment() {
		$comment_id = I('comment_id', "0", "intval");
		$r = Logic('BoxSns', 'Comment')->del($comment_id);
		echo json_encode($r);
	}

	public function add() {
		$this->group_id = $group_id = I('group_id', 0, "intval");
		$this->type = "group";
		$this->data = BoxModel("sns_group")->load($group_id);
		$this->display();
	}

}
